package com.tulele.vtool.handler;

import com.tulele.vtool.model.ArticleInfo;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;

import io.lkt.common.dto.ArticleInfoTemp;
import io.lkt.common.utils.WebSpiderThreadUtil;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class AATestHandler {
    @PostMapping(value = "/myTest", produces = "application/json;charset=UTF-8")
    public RespData myTest(@RequestHeader("userId") String userId) {


        ArticleInfo bArticleInfo = new ArticleInfo();
        String userSendContent = "https://mp.weixin.qq.com/s/OCSOUrJRsiS44bvi4SZsLQ";
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("mp.weixin.qq.com")) {
            ArticleInfoTemp item = WebSpiderThreadUtil.getWeiXinPage(userSendContent.trim().replaceAll("\"", ""));

            bArticleInfo.setArticleTitle(item.getArticleTitle());
            bArticleInfo.setArticleDesc(item.getArticleDesc());
            bArticleInfo.setArticleImgUrl(item.getArticleImgUrl());
            bArticleInfo.setArticleContent(item.getArticleContent());
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(bArticleInfo);
        respData.setMsg("成功");
        return respData;

    }
}
